package com.ruoyi.web.controller.safety;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.safety.domain.SafetyPointCount;
import com.ruoyi.safety.service.ISafetyPointCountService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 测点统计信息数据Controller
 *
 * @author ruoyi
 * @date 2024-10-30
 */
@RestController
@RequestMapping("/safety/count")
public class SafetyPointCountController extends BaseController
{
    @Autowired
    private ISafetyPointCountService safetyPointCountService;

    /**
     * 查询测点统计信息数据列表
     */
    @PreAuthorize("@ss.hasPermi('safety:count:list')")
    @GetMapping("/list")
    public TableDataInfo list(SafetyPointCount safetyPointCount)
    {
        startPage();
        List<SafetyPointCount> list = safetyPointCountService.selectSafetyPointCountList(safetyPointCount);
        return getDataTable(list);
    }

    /**
     * 导出测点统计信息数据列表
     */
    @PreAuthorize("@ss.hasPermi('safety:count:export')")
    @Log(title = "测点统计信息数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SafetyPointCount safetyPointCount)
    {
        List<SafetyPointCount> list = safetyPointCountService.selectSafetyPointCountList(safetyPointCount);
        ExcelUtil<SafetyPointCount> util = new ExcelUtil<SafetyPointCount>(SafetyPointCount.class);
        util.exportExcel(response, list, "测点统计信息数据数据");
    }

    /**
     * 获取测点统计信息数据详细信息
     */
    @PreAuthorize("@ss.hasPermi('safety:count:query')")
    @GetMapping(value = "/{pointCode}")
    public AjaxResult getInfo(@PathVariable("pointCode") String pointCode)
    {
        return success(safetyPointCountService.selectSafetyPointCountByPointCode(pointCode));
    }

    /**
     * 新增测点统计信息数据
     */
    @PreAuthorize("@ss.hasPermi('safety:count:add')")
    @Log(title = "测点统计信息数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SafetyPointCount safetyPointCount)
    {
        return toAjax(safetyPointCountService.insertSafetyPointCount(safetyPointCount));
    }

    /**
     * 修改测点统计信息数据
     */
    @PreAuthorize("@ss.hasPermi('safety:count:edit')")
    @Log(title = "测点统计信息数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SafetyPointCount safetyPointCount)
    {
        return toAjax(safetyPointCountService.updateSafetyPointCount(safetyPointCount));
    }

    /**
     * 删除测点统计信息数据
     */
    @PreAuthorize("@ss.hasPermi('safety:count:remove')")
    @Log(title = "测点统计信息数据", businessType = BusinessType.DELETE)
	@DeleteMapping("/{pointCodes}")
    public AjaxResult remove(@PathVariable String[] pointCodes)
    {
        return toAjax(safetyPointCountService.deleteSafetyPointCountByPointCodes(pointCodes));
    }
}
